package graphicView;

import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JPanel;

import model.ClassImpl;

//This is a test JPanel to check if the drawing method draws properly.
/**
 * Team EBE
 * 
 * DrawRectPanel.java is not used in the actual program, it is a prototype for
 * ClassGraphicObject.java; still included in the project for reference and
 * future work
 * 
 */
public class DrawRectPanel extends JPanel {

	ClassImpl classObject = new ClassImpl();

	public void paintComponent(Graphics g) {
		super.paintComponent(g);

		classObject.setName("testClass1()");
		classObject.setoX(50);
		classObject.setoY(50);
		char mychar = '+';
		classObject.addAttribute("testName", "testType", mychar);

		Font title = new Font("serif", Font.PLAIN, 20);
		Font attr = new Font("serif", Font.PLAIN, 12);

		g.setColor(Color.lightGray);
		g.fillRect(classObject.getoX(), classObject.getoY(), 200, 20);

		g.setColor(Color.black);
		g.drawRect(classObject.getoX(), classObject.getoY(), 200, 200);

		g.setFont(title);
		g.drawString(classObject.getName(), classObject.getoX() + 5,
				classObject.getoY() + 15);

		g.setFont(attr);

		for (int n = 0; n < classObject.getAttributes().size(); n++) {
			String str = getNthAttributeLine(n);
			g.drawString(str, classObject.getoX(), classObject.getoY() + 40
					+ 22 * n);

		}
	}

	private String getNthAttributeLine(int n) {
		String str = " "
				+ this.classObject.getAttributes().elementAt(n)
						.getVisibility() + " "
				+ this.classObject.getAttributes().elementAt(n).getType()
				+ " "
				+ this.classObject.getAttributes().elementAt(n).getName() + "";

		return str;
	}

	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.setForeground(Color.white);
		frame.setTitle("DrawRect");
		frame.setSize(800, 800);
		frame.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
		Vector<String> test = new Vector<String>();
		test.add("test1");
		test.add("test2");

		// drawClass(50,50, "test", test,Graphics g);

		Container contentPane = frame.getContentPane();

		contentPane.add(new DrawRectPanel());

		frame.show();
	}

}